package com.waiter.agent;

import java.util.Calendar;

import manager.AppManager;
import models.DTO_MonAn;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

public class BillHistoryActivity extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.billhistory);

		Button btnAddBill = (Button) findViewById(R.id.buttonAddbill);
		btnAddBill.setOnClickListener(EventHandler());

		// ScrollView sclview = (ScrollView) findViewById(R.id.idbillscroll);
		LinearLayout ln = (LinearLayout) findViewById(R.id.lnitem);
		Calendar c = Calendar.getInstance();

		for (int i = 1; i <= 10; i++) {
			ln.addView(CreateItem("" + i,
					c.get(Calendar.DATE) + "/" + (c.get(Calendar.MONTH) + 1) + "/"
							+ c.get(Calendar.YEAR), c.get(Calendar.HOUR_OF_DAY)
							+ ":" + c.get(Calendar.MINUTE)));
		}
	}

	public View CreateItem(String sequence, String date, String time) {

		LayoutInflater inflater = (LayoutInflater) this
				.getSystemService(this.LAYOUT_INFLATER_SERVICE);
		View item = inflater.inflate(R.layout.billhistory_item, null);

		TextView tvStt = (TextView) item.findViewById(R.id.tvStt);
		tvStt.setText(sequence);

		TextView tvDate = (TextView) item.findViewById(R.id.tvDate);
		tvDate.setText(date);

		TextView tvTime = (TextView) item.findViewById(R.id.tvTime);
		tvTime.setText(time);

		item.setOnClickListener(EventHandler());
		return item;
	}

	public OnClickListener EventHandler() {
		return new OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (v.getId() == R.id.buttonAddbill) {
					Intent intent = new Intent(getApplicationContext(),
							OrderBillActivity.class);
					startActivity(intent);

				} else {
					AppManager.getInstance().setState(
							AppManager.ADD_FOOD_NEW_BILL);

					DTO_MonAn food = new DTO_MonAn();
					food.setTenMon("Hamburger");
					food.setGia(5000);
					AppManager.getInstance().addFood(food);

					food = new DTO_MonAn();
					food.setTenMon("Hotdog");
					food.setGia(6000);
					AppManager.getInstance().addFood(food);

					food = new DTO_MonAn();
					food.setTenMon("Pizza");
					food.setGia(10000);
					AppManager.getInstance().addFood(food);

					Intent intent = new Intent(getApplicationContext(),
							OrderBillActivity.class);
					startActivity(intent);

				}
			}
		};
	}
}